import request from '@/utils/request';

const productPath = '/product/product';
const productV1Path = '/product/v1/product';

/**
 * 获取商城福利购秒杀商品
 */
export async function getSpikeProduct() {
  return request({
    url: `${productPath}/spike/getSpikeProduct`,
    method: 'GET',
    unNeedToken: true,
  });
}

/**
 * 获取商品分类
 */
export async function getCategory() {
  return request({
    url: `${productPath}/category/getCategory`,
    method: 'GET',
    unNeedToken: true,
  });
}

/**
 * 获取行业分类
 */
export async function getIndustryServer() {
  return request({
    url: `${productPath}/industry`,
    method: 'POST',
  });
}

/**
 * 获取二级行业分类
 */
export async function getSecondIndustryServer({ id }) {
  return request({
    url: `${productPath}/getProductSecondIndustry/${id}`,
    method: 'GET',
  });
}

/**
 * 获取商城福利购按分类获取商品
 */
export async function getRecommendProduct(data) {
  return request({
    url: '/product/v1/product/recommend',
    method: 'POST',
    unNeedToken: true,
    data: data,
  });
}

/**
 * 获取商品详情
 */
export async function getDetail(data) {
  const { id } = data;
  return request({
    url: `${productPath}/getDetail/${id}`,
    method: 'GET',
    unNeedToken: true,
  });
}

/**
 * 获取商品sku属性价格
 */
export async function getOptionPrice(data) {
  return request({
    url: `${productPath}/getOptionPrice`,
    method: 'POST',
    unNeedToken: true,
    data: data,
  });
}

/**
 * 添加商品到购物车
 */
export async function addProduct(data) {
  return request({
    url: `${productV1Path}/productCar/addProduct`,
    method: 'POST',
    data: data,
  });
}

/**
 * 获取省钱专区商品
 */
export async function getCheaperProduct(data) {
  return request({
    url: `${productPath}/discount`,
    method: 'POST',
    unNeedToken: true,
    data: data,
  });
}

/**
 * 获取商户主页推荐商品
 */
export async function getRecommendByOrgService(data) {
  const { page, pageSize, sort } = data;
  return request({
    url: `${productPath}/recommendByOrg?page=${page}&pageSize=${pageSize}&sort=${sort}`,
    method: 'GET',
  });
}

/**
 * 获取购物车商品数量
 */
export async function getProductTotalNumService(data, fullResponse) {
  return request({
    url: `${productV1Path}/productCar/selectProductTotalNumByUserId`,
    method: 'GET',
    data,
    fullResponse,
  });
}

// 商品详情配送费
export async function freightServer(data) {
  return request({
    url: `/product/freightTemplate/productDetailFreightTemplateFee`,
    method: 'POST',
    data,
  });
}

// 推荐商品列表
export async function topProductListServer(data) {
  return request({
    url: '/product/featuredFirstProduct/topProductList',
    method: 'POST',
    data,
  });
}

// 商城商品分组列表
export async function productGroupsServer(merchantId) {
  return request({
    url: `/product/app/productReleaseAppGroup/selectProductReleaseGroup/${merchantId}`,
    method: 'GET',
  });
}

// 商城分组商品列表
export async function productGroupListServer(data) {
  return request({
    url: `/product/product/getGroupProductRelease`,
    method: 'POST',
    data,
  });
}

// 获取配置商品
export async function appProductListServer(data) {
  return request({
    url: `/product/product/selectAppProduct`,
    method: 'POST',
    data,
  });
}

// 获取活动商品分页列表
export async function activityProductListServer(data) {
  return request({
    url: `/product/product/fineActivity/getActivityProductPageList`,
    method: 'POST',
    data,
  });
}
